 #This script performs OLS and quantile (linear) regressions for 4 species of skinks, and prepares a datafile to compare residual abundance to microclimate

#Clear workspace

rm(list=ls())

in.dir = "C:/R/In/"
out.dir = "C:/R/Out/"

#Set working directory
setwd(in.dir)

#load necessary libraries

library("SDMTools")
library("quantreg")
library("adehabitat")

#Import the dataset for analysis

samples= read.csv("samplesmaster.csv",header=T)
georef = read.csv("georefmaster.csv", header=T)
s.fields = names(samples)
g.fields = names(georef)

#First begin by working with the samples data, plotting relationships between all variables and sample abundance
#Use a for loop to perform both quantile and OLS regression between all variables and samples abundance
num=0
for(fields in s.fields)

  {
  num=num+1
  png(paste(out.dir,fields,".png", sep=""), height=800, width=800)
  plot(samples$[num], rawdata$cr_abund, xlab=fields, ylab="abund", main="CARRUBR")
  dev.off()

  }
